//
//  ReadCollectionViewCell.m
//  悦读
//
//  Created by dllo on 15/5/26.
//  Copyright (c) 2015年 贾建兴. All rights reserved.
//

#import "ReadCollectionViewCell.h"

@implementation ReadCollectionViewCell


- (void)dealloc
{
    
    [_textView release];
    [super dealloc];
}


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

        [self createView];
    }
    return self;
}


#pragma mark - 
#pragma mark 为textView添加轻扫手势进行翻页
- (void)createView
{
    self.textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - 5)];
   [self addSubview:self.textView];
    self.textView.editable = NO;
//    self.textView.backgroundColor = [UIColor grayColor];
    //隐藏滚动条
    self.textView.showsVerticalScrollIndicator = NO;
    [self.textView release];

}




- (void)getText:(NSString *)text font:(NSInteger)fontNum textColor:(UIColor *)color chapter:(NSString *)chapter
{
    //根据获取的章节内容,设定textView的滚动范围
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontNum]};
    CGRect rect = [text boundingRectWithSize:CGSizeMake(100000, self.textView.frame.size.height) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
//    //如果内容范围大于self.textView自身大小,则滚动范围为内容设定大小

    if(rect.size.width > self.frame.size.width)
    {
        self.textView.contentSize = CGSizeMake(self.textView.frame.size.width, rect.size.height + 20);
    } else
    {
        self.textView.contentSize = CGSizeMake(0, self.frame.size.height);
    }
    NSString *str = [NSString stringWithFormat:@"\n%@\n%@\n", chapter, text];
//    self.chapterLabel.text = chapter;
    if (str.length == 0) {
        self.textView.text = @"..";
    } else {
        self.textView.text = str;
    }
    
    self.textView.scrollsToTop = YES;
    self.textView.font = [UIFont systemFontOfSize:fontNum];
    [self.textView setBackgroundColor:color];
    
}

@end
